package com.keda;


import org.apache.http.HttpHost;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

public class test_get {
    public static void main(String[] args) throws IOException {

        //创建es 客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost",9200))
        );

        // 查询数据
       GetRequest  request=new GetRequest();
            request.index("user").id("1001");


        GetResponse response = esClient.get(request, RequestOptions.DEFAULT);

        //  {"name":"张三","sex":"女","age":20}
        System.out.println(response.getSourceAsString());


        //关闭es客户端
        try {
            esClient.close();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
